package com.bao.springboot.first.service;

import com.bao.springboot.first.domain.User;
import com.bao.springboot.first.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author ：baoliangquan
 * @date ：Created in 2019/11/14 0014 15:00
 * @description：
 * @modified By：
 * @version: $
 */
@Component
public class UserService {

    @Autowired
    private UserRepository userRepository;

    public List<User> getAll(){
        return userRepository.findAll();
    }

    public List<User> findUserByLessAge(String age){
        return userRepository.findByAgeIsLessThan(age);
    }

    public int save(User user) {
        User u =  userRepository.save(user);
        System.out.println("成功保存");
        return 1;
    }

    public int delete(Long id) {
        User user = userRepository.findUserById(id);
        userRepository.delete(user);
        return 1;
    }
}
